﻿namespace MicroCloud.SMS.Database
{
    /// <summary>
    /// 验证码短信记录实体映射配置
    /// </summary>
    public class VerifyCodeConfiguration : EntityTypeConfigurationBase<VerifyCode, long>
    {
        #region "方法"
        #region "重写以实现实体类型各个属性的数据库配置"
        /// <summary>
        /// 重写以实现实体类型各个属性的数据库配置
        /// </summary>
        /// <param name="builder">实体类型创建器</param>
        public override void Configuration(EntityTypeBuilder<VerifyCode> builder)
        {
            //builder.HasIndex(m => new { m.PhoneNumber, m.Provider, m.BizId, m.VerifyCode, m.Verified }).HasDatabaseName("IX_CaptchaSent_PhoneBiz").IsUnique(false);
            //builder.HasIndex(m => m.SendDate).HasDatabaseName("IX_CaptchaSent_SendDate").IsUnique(false);
            builder.HasIndex(m => new { m.PhoneNumber, m.Provider, m.BizId, m.VerifyCode, m.Verified }).SetIndex("PhoneBiz");
            builder.HasIndex(m => m.SendDate).SetIndex("SendDate");
            switch (DbContextOptions?.DatabaseType)
            {
                case DatabaseType.SqlServer:
                case DatabaseType.PostgreSql:
                case DatabaseType.Oracle:
                    //builder.HasIndex(m => m.Provider).HasDatabaseName("IX_CaptchaSent_Provider").IsUnique(false);
                    builder.HasIndex(m => m.Provider).SetIndex("Provider");
                    break;
            }

            ConfigurationAppend(builder);
        }
        #endregion

        #endregion

    }

}
